package com.atguigu.day04;

import java.util.concurrent.*;

//自定义线程池
public class MyThreadPoolDemo2 {
    public static void main(String[] args) {

        ExecutorService threadPool = new ThreadPoolExecutor(
//                Runtime.getRuntime().availableProcessors(),
                2,
                5,
                3,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(3),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        try {
            for (int i = 1; i <= 8; i++) {
                int finalI = i;
                threadPool.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"受理第"+ finalI +"个顾客");
                    //线程睡眠几秒
                    try {TimeUnit.SECONDS.sleep(1);} catch (InterruptedException e) {throw new RuntimeException(e);}
                });
            }

        }finally {

        }
    }
}
